﻿using JESAI.Application.Abstractions.Dtos;
using JESAI.Application.Abstractions.Sys.Querys;
using JESAI.Application.Abstractions.Workflow;
using JESAI.Application.Abstractions.Workflow.Dtos;
using JESAI.Application.Abstractions.Workflow.Querys;
using JESAI.AutoMapper.ObjectMapping;
using JESAI.Framework.Filters;
using JESAI.Platform.WebApi.Vos.Sys;
using JESAI.Platform.WebApi.Vos.Workflow;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace JESAI.Platform.WebApi.Controllers.Workflow
{
    /// <summary>
    /// This is the controller for InnerForm related operations.
    /// </summary>
    [ApiController]
    [Route("api/v1/[controller]/[action]")]
    [Authorize("permission")]
    [IgnoreResultHandlerAttribute]
    public class InnerFormController : ControllerBase
    {
        private readonly IInnerFormService _innerFormService;

        /// <summary>
        /// Constructor for the InnerFormController.
        /// </summary>
        /// <param name="innerFormService"></param>
        public InnerFormController(IInnerFormService innerFormService)
        {
            _innerFormService = innerFormService;
        }

        /// <summary>
        /// This method is used to get the list of InnerForms based on the given query.
        /// </summary>
        /// <param name="innerFormPageQuery"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<BasePageOutput<List<InnerFormResponse>>> GetInnerFormPageList([FromQuery] InnerFormPageQuery innerFormPageQuery)
        {
            var innerFormPageList = await _innerFormService.GetInnerFormPageList(innerFormPageQuery);
            return innerFormPageList.MapTo<BasePageOutput<List<InnerFormResponse>>>();
        }

        [HttpGet]
        public async Task<BaseOutput<List<InnerFormResponse>>> GetInnerFormAllList()
        {
            var innerFormPageList = await _innerFormService.GetInnerFormAllList();
            return new BaseOutput<List<InnerFormResponse>> { Data = innerFormPageList.MapTo<List<InnerFormResponse>>() };
        }

        [HttpPost]
        public async Task<BaseOutput> SaveOrUpdateInnerForm([FromBody] InnerFormInput innerFormInput)
        {
            await _innerFormService.SaveOrUpdateInnerForm(innerFormInput);

            return new BaseOutput();
        }

        [HttpDelete]
        public async Task<BaseOutput> DeleteInnerFormById(string innerFormId)
        {
            await _innerFormService.DeleteInnerFormById(innerFormId);
            return new BaseOutput();
        }

        [HttpDelete]
        public async Task<BaseOutput> DeleteInnerFormByIds(string[] innerFormIds)
        {
            await _innerFormService.DeleteInnerFormByIds(innerFormIds);
            return new BaseOutput();
        }

        [HttpPost]
        public async Task<BaseOutput> SaveOrUpdateNodeInnerForms([FromBody] List<NodeFormInput> innerFormInputs)
        {
            await _innerFormService.SaveOrUpdateNodeForms(innerFormInputs);
            return new BaseOutput();
        }

        [HttpPost]
        public async Task<BaseOutput> SaveOrUpdateNodeForms([FromBody] NodeFormInput innerFormInput)
        {
            await _innerFormService.SaveOrUpdateNodeForm(innerFormInput);
            return new BaseOutput();
        }

        [HttpGet]
        public async Task<BaseOutput> DeleteNodeForm(string innerFormId)
        {
            await _innerFormService.DeleteNodeForm(innerFormId);
            return new BaseOutput();
        }

        [HttpGet]
        public async Task<BaseOutput<List<NodeFormResponse>>> GetNodeFormList(string nodeId)
        {
            var innerNodeFormList = await _innerFormService.GetNodeFormList(nodeId);
            return new BaseOutput<List<NodeFormResponse>> { Data = innerNodeFormList.MapTo<List<NodeFormResponse>>() };
        }

        [HttpGet]
        public async Task<BaseOutput<NodeFormResponse>> GetNodeForm(string Id)
        {
            var innerNodeForm = await _innerFormService.GetNodeForm(Id);
            return new BaseOutput<NodeFormResponse> { Data = innerNodeForm.MapTo<NodeFormResponse>() };
        }
    }
}
